#!/usr/bin/perl

use lib "./../cgi-bin/";
use SHELL::Command;
use config;

#use Cache::Memcached;
#my $cache =
  #Cache::Memcached->new( { servers => ["192.168.59.228:11211"], debug => 0 } );

sub svn_cat {
	my $path = shift;
	my $file = $ENV{'SVNROOT'} . $path;
	return `svn cat $file`;
}

@projectsList = (
	'decisions',                   'clib',
	'rt',                          'rt-kgor_1_10_0_128',
	'nds',                         'datasrc',
	'ssi',                         'ssi-1_5_1_48-bassoi-1_5_1_48',
	'lingui',                      'lingui-qt4-0_0_0_64',
	'clibgui',                     'clibgui-qt3-0_0_0_182',
	'navsol-navsol-0_0_0_0-bmcbc', 'pienap',
	'ppclient',                    'reportltx'
);
#unless ( $cache->get("DATA") ) {
#	my %DATA;
#	print "BEGIN CREATE DATA\n";
#	foreach my $name (@projectsList) {
#		my ( $proj, $branch ) = $name =~ m/^(\w+)(.*)/;
#		if ($branch) {
#
#			# branches
#			$branch =~ s/-//;
#			my $projectConf =
#			  &svn_cat( $proj . '/branches/' . $branch . '/src/project.conf' );
#			my ($ARCH) = $projectConf =~ m/ARCHS := (.+)/;
#			my ($CFGS) = $projectConf =~ m/CFGS := (.+)/;
#			$DATA{$name}{'ARCH'} = [ split / /, $ARCH ];
#			$DATA{$name}{'CFGS'} = [ split / /, $CFGS ];
#			$DATA{$name}{'SVN_URL'} =
#			  $ENV{'SVNROOT'} . 'branches/' . $branch . '/';
#			my $version =
#			  &svn_cat( $proj . '/branches/' . $branch . '/src/version' );
#			chomp($version);
#			$DATA{$name}{'VERSION'} = $version;
#		}
#		else {
#
#			# trunk
#			my $projectConfPath = $proj . '/trunk/src/project.conf';
#			my $projectConf     = &svn_cat($projectConfPath);
#			my ($ARCH) = $projectConf =~ m/ARCHS := (.+)/;
#			my ($CFGS) = $projectConf =~ m/CFGS := (.+)/;
#			$DATA{$name}{'ARCH'} = [ split / /, $ARCH ];
#			$DATA{$name}{'CFGS'} = [ split / /, $CFGS ];
#			$DATA{$name}{'SVN_URL'} = $ENV{'SVNROOT'} . 'trunk/';
#			my $version = &svn_cat( $proj . '/trunk/src/version' );
#			chomp($version);
#			$DATA{$name}{'VERSION'} = $version;
#		}
#	}
#	$cache->set( "DATA", {%DATA}, 60 * 60 );
#	print "END CREATE DATA\n";
#}

#if ( $cache->get("DATA") ) {
	my $DATA = &getData();

	for my $proj ( keys %$DATA ) {
		print "project: $proj\n";
		for $pole ( keys %{ $DATA->{$proj} } ) {
			print "   $pole=$DATA->{$proj}{$pole}\n"
			  if ( ( $pole ne 'ARCH' ) && ( $pole ne 'CFGS' ) );
			if ( $pole eq 'ARCH' ) {
				print "   ARCH:\n";
				foreach my $arch ( @{ $DATA->{$proj}{'ARCH'} } ) {
					print "       $arch\n";
				}
			}
			if ( $pole eq 'CFGS' ) {
				print "   CFGS:\n";
				foreach my $cfg ( @{ $DATA->{$proj}{'CFGS'} } ) {
					print "       $cfg\n";
				}
			}
		}
	}

#}
